/*
 * Task 2. Arrays - neighbouring numbers
 */
import java.util.*;
import java.io.*;

/**
 * Class for searching closest neighbour numbers
 * 
 * @author Vlad Oblamskyi
 */
class NeighbouringNumbers {
    private static final int INIT_INDEX = -1;
    
    /* Minimal number of elements */
    private static final int MIN_ELEMENTS_NUMBER = 2;
    
    /**
     * Searching index of the first element from pair, which has minimal
     * distance
     */
    public static int getMinDistanceIndex(int[] array) {
        if (array.length < MIN_ELEMENTS_NUMBER)
            throw new IllegalArgumentException("Not enough elements!");
        
        int minDistance = Integer.MAX_VALUE;
        int minDistanceIndex = INIT_INDEX;
        
        for (int currentIndex = 1; currentIndex < array.length; currentIndex++) {
            int currentDistance = Math.abs(array[currentIndex] 
                                           - array[currentIndex - 1]);
            if (currentDistance < minDistance) {
                minDistance = currentDistance;
                minDistanceIndex = currentIndex - 1;
            }
        }        
        return minDistanceIndex;
    }
    
    public static int[] getArrayInput(Scanner in) {
        System.out.print("Enter array size: ");
        int size = in.nextInt();
        
        int[] array = new int[size];
        
        for (int index = 0; index < size; index++) {
            System.out.print("Enter " + index + " element: ");
            array[index] = in.nextInt();
        }        
        
        return array;
    }
    
    public static void printResult(String result) {
        System.out.println("Result: " + result);
    }
    
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        
        int[] numbers = getArrayInput(in);
        int result = getMinDistanceIndex(numbers);
        
        printResult("index = " + result);
        
        in.close();
    }
}